package com.nearsoft.academy;


import android.graphics.Point;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 8/20/12
 * Time: 12:57 PM
 * To change this template use File | Settings | File Templates.
 */
public class Arrow {
    private Point start;
    private Point end;
    private Point left;
    private Point right;

    public Point getEnd() {
        return end;
    }

    public Point getLeft() {
        return left;
    }

    public Point getRight() {
        return right;
    }

    public Point getStart() {
        return start;
    }

    public Arrow(Point start, Point end){
        this.start = start;
        this.end = end;
        getLeftAndRightPoints();
    }

    private void getLeftAndRightPoints() {
        this.left = new Point();
        this.right = new Point();

        float arrowLength = Math.abs((float)Math.hypot(end.x - start.x, end.y - start.y));
        float[] polarTop1 = new float[2];
        polarTop1[0] = arrowLength / 2f;
        // Sum the 45 degrees (in radians PI/4) with the current line slope
        polarTop1[1] = (float)(Math.atan2(end.y - start.y, end.x - start.x) + Math.PI * 0.75f);

        float[] cartesian = Graphics.polarToCartesian(polarTop1[0], polarTop1[1]);

        left.x = (int)(end.x + cartesian[0]);
        left.y = (int)(end.y + cartesian[1]);

        float[] polarTop2 = new float[2];
        polarTop2[0] = polarTop1[0];
        // Sum the 45 degrees (in radians PI/2) with the current line slope
        polarTop2[1] = (float)(polarTop1[1] - 1.5 * Math.PI);

        float[] cartesianTop2 = Graphics.polarToCartesian(polarTop2[0], polarTop2[1]);
        right.x = (int)(end.x + cartesianTop2[0]);
        right.y = (int)(end.y + cartesianTop2[1]);
    }


}
